package cn.kailangtu.commontools;

import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.net.wifi.WifiManager;

import java.util.HashMap;

public class UsbUtils {

    static int pid = 29987;
    private static boolean usbConnected = false;

    public static HashMap<String, UsbDevice> getUserDevices(Context context){
        UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
        int size = usbManager.getDeviceList().size();
        HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
        boolean currentPid = false;
        for(String key : deviceList.keySet())
        {
            if(deviceList.get(key).getProductId() == pid)
            {
                currentPid = true;
                break;
            }
        }

        usbConnected = currentPid;
        return deviceList;
    }

    public static boolean isUsbConnected() {
        return usbConnected;
    }

    public static void setUsbConnected(boolean usbConnected) {
        UsbUtils.usbConnected = usbConnected;
    }
}
